package chap3_8;

import java.io.*;

/**
 * @author https://gitee.com/W_Jun
 * @date 2021-12-13 21:53
 * @Description 字符缓冲流
 */
public class BufferedStreamDemo01 {
    public static void main(String[] args) throws IOException {
        //字符缓冲输出流
        /*
        FileWriter fw = new FileWriter("chapter03-字符流\\bw.txt");
        BufferedWriter bw = new BufferedWriter(fw);
        */
        BufferedWriter bw = new BufferedWriter(new FileWriter("chapter03-字符流\\bw.txt"));
        bw.write("hello\r\n");
        bw.write("world\r\n");
        bw.close();

        //字符缓冲输入流
        BufferedReader br = new BufferedReader(new FileReader("chapter03-字符流\\bw.txt"));
        //一次读一个字符
/*        int ch;
        while ((ch = br.read()) != -1) {
            System.out.print((char) ch);
        }
        br.close();*/

        //一次读一个字符数组
        char[] chs = new char[1024];
        int len;
        while ((len = br.read(chs)) != -1) {
            System.out.println( new String(chs, 0, len));
        }
        br.close();
    }
}